package com.bawei.park2301.user

import android.content.Intent
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.libs_base.mvvm.BaseActivity
import com.bawei.park2301.MainActivity
import com.bawei.park2301.databinding.ActivityLoginBinding
import com.blankj.utilcode.util.ToastUtils
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class LoginActivity : BaseActivity<ActivityLoginBinding,UserViewModel>() {
    override fun initView() {
        binding.btnLogin.setOnClickListener {
            val account = binding.etAccount.text
            val pwd = binding.etPassword.text
            if (account.isEmpty() || pwd.isEmpty()) {
                ToastUtils.showLong("请输入用户名密码")
                return@setOnClickListener
            }

//            手机号
            if (!account.matches(Regex("1[3-9]\\d{9}"))) {
                ToastUtils.showLong("请输入正确的手机号")
                return@setOnClickListener
            }
            viewModel.login(account.toString(),pwd.toString())
        }
    }

    override fun initData() {
        viewModel.loginData.observe(this){
            ToastUtils.showLong(it.message)
            if (it.code == 200) {
                ARouter.getInstance().build("/app/MainActivity").navigation()
            }
        }
    }


}